export function buildMenuTree(menuList) {
    const tree = [];
    const map = new Map();
    menuList = menuList.sort((a, b) => b?.sortOrder - a?.sortOrder)
    // console.log(menuList)
    // 初始化映射
    menuList.forEach(item => {
        map.set(item.id, {...item, children: []});
    });

    // 构建树
    menuList.forEach(item => {
        if (!item.pid) {
            tree.push(map.get(item.id));
        } else {
            const parent = map.get(item.pid);
            if (parent) parent.children.push(map.get(item.id));
        }
    });
    return tree;
}
